package com.yunwushanhe.bean.ret;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.yunwushanhe.enums.AppHttpCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = -41987030913876666L;

    private Integer code = AppHttpCodeEnum.SUCCESS.getCode();
    private String msg = AppHttpCodeEnum.SUCCESS.getMsg();
    private T data;

    public static <T> ResponseResult<T> ok() {
        return new ResponseResult<>();
    }

    public static <T> ResponseResult<T> ok(int code, String msg) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> ResponseResult<T> ok(T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        return result;
    }

    public static <T> ResponseResult<T> error(int code, String msg) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> ResponseResult<T> error(AppHttpCodeEnum enums){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(enums.getCode());
        result.setMsg(enums.getMsg());
        return result;
    }

    public static <T> ResponseResult<T> error(AppHttpCodeEnum enums, String msg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(enums.getCode());
        result.setMsg(msg);
        return result;
    }

}
